{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "current working dir [E:\\SHARE\\11.rnn\\quiz-w10-code]\n",
      "change wording dir to [E:\\SHARE\\11.rnn\\quiz-w10-code]\n",
      " --output_dir=./rnn_log --text=QuanSongCi.txt --num_steps=32 --batch_size=3 --dictionary=dictionary.json --reverse_dictionary=reverse_dictionary.json --learning_rate=0.001\n",
      "################    train    ################\n",
      "################    eval    ################\n"
     ]
    }
   ],
   "source": [
    "run train_eval.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['潘', '阆', '\\n', '\\n', '酒', '泉', '子', '（', '十', '之', '一', '）', '\\n', '\\n', '长', '忆', '钱', '塘', '，', '不', '是', '人', '寰', '是', '天', '上', '。', '万', '家', '掩', '映', '翠', '微', '间', '。', '处', '处', '水', '潺', '潺', '。', '\\n', '\\n', '异', '花', '四', '季', '当', '窗', '放', '。', '出', '入', '分', '明', '在', '屏', '障', '。', '别', '来', '隋', '柳', '几', '经', '秋', '。', '何', '日', '得', '重', '游', '。', '\\n', '\\n', '酒', '泉', '子', '（', '十', '之', '二', '）', '\\n', '\\n', '长', '忆', '钱', '塘', '，', '临', '水', '傍', '山', '三', '百', '寺', '。', '僧', '房']\n",
      "Data size 1903073\n",
      "dictionary.json\n",
      "==============================\n",
      "[[1503 1828    2    2   40  613   47    9  111  117    8   10]\n",
      " [ 256  149  196  284   34  129    1   87   79  663   80   30]\n",
      " [ 138   35 3274  224 2519    1  120  195  878    1  120  195]\n",
      " [ 733  257   11    9  121  746   10    2    2  255  298   23]\n",
      " [  13  403    1    2    2  162  185  169  539  497 1324    1]\n",
      " [ 238  190  176    1  254    5   39   34   87  479 1285 3057]\n",
      " [  60  109  130   10    2    2  154  323  266 3265    3   72]\n",
      " [ 554    1  441  187 1154  856    3  809    7  205 3223    3]]\n",
      "[[1828    2    2   40  613   47    9  111  117    8   10    2]\n",
      " [ 149  196  284   34  129    1   87   79  663   80   30   86]\n",
      " [  35 3274  224 2519    1  120  195  878    1  120  195  878]\n",
      " [ 257   11    9  121  746   10    2    2  255  298   23  116]\n",
      " [ 403    1    2    2  162  185  169  539  497 1324    1 1195]\n",
      " [ 190  176    1  254    5   39   34   87  479 1285 3057    1]\n",
      " [ 109  130   10    2    2  154  323  266 3265    3   72  126]\n",
      " [   1  441  187 1154  856    3  809    7  205 3223    3  100]]\n",
      "==============================\n"
     ]
    }
   ],
   "source": [
    "\n",
    "import json\n",
    "import logging\n",
    "import os\n",
    "\n",
    "import tensorflow as tf\n",
    "\n",
    "import utils\n",
    "from model import Model\n",
    "from utils import read_data\n",
    "from utils import get_train_data\n",
    "\n",
    "from flags import parse_args\n",
    "FLAGS, unparsed = parse_args()\n",
    "\n",
    "\n",
    "logging.basicConfig(\n",
    "    format='%(asctime)s - %(levelname)s - %(filename)s:%(lineno)d - %(message)s', level=logging.DEBUG)\n",
    "\n",
    "vocabulary = read_data(FLAGS.text)\n",
    "print(vocabulary[:100])\n",
    "print('Data size', len(vocabulary))\n",
    "#data_index = 0\n",
    "#\n",
    "\n",
    "#准备好字典以后就可以不用这句了\n",
    "#data, count, dictionary, reversed_dictionary = build_dataset(vocabulary, 5000)\n",
    "\n",
    "\n",
    "print(FLAGS.dictionary)\n",
    "with open(FLAGS.dictionary, encoding='utf-8') as inf:\n",
    "    dictionary = json.load(inf, encoding='utf-8')\n",
    "\n",
    "with open(FLAGS.reverse_dictionary, encoding='utf-8') as inf:\n",
    "    reverse_dictionary = json.load(inf, encoding='utf-8')\n",
    "\n",
    "for dl in get_train_data(vocabulary, 8, 12, dictionary):\n",
    "    print(\"==============================\")\n",
    "    print(dl[0])\n",
    "    print(dl[1])\n",
    "    print(\"==============================\")\n",
    "    break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5,1,'钟形函数')"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAEFCAYAAADt1CyEAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAEDBJREFUeJzt3X+sZHV5x/H3h2VBuouytLerWCHdhtYfUPxxq10BcyVAJamBUJVNFBOt3WgV0x+2xbhqS7ZpQwxpq1llkVYSjRar0KyVurZ2C1K03Q2ligpSXGoxG1YXWCHWRnz6x5x1bse9e+fOnTuX++X9SiZ77swzh+d879zPnPmec4ZUFZKkdh213A1IkpaWQS9JjTPoJalxBr0kNc6gl6TGGfRasZJck+T1A/ddkuSjA/cdfZjnHjNr+XlJfnLg8WOTZMg+3pLkSUk+l+T0JL+X5MlJrk7ykoVtlTR+Br1WpCRrgVcCuwce+j7wvwP37UhyIMmdSe5Ksh/45249TwZuAH4UyElOAPYAu5MM3h5NUkleMGv9RwNbgB8Aa4BNVXUQOAf477FttDSiH9vTkVaIt9N7/b6/C+4/AJ4GnAasTzLT1d1SVRck+Rjwp8AJ9IL4jUmOAv4KuKaqbji04qp6qFsPAElOAi4FzgI+BVxXVd/oHnsS8C2ggHXADHBztye/tqru7eqOrarvL8lISPNwj14rTpIzgTcAz6mqM6vqIuC3gd8AngX8NL1QvgFYPcc6VgEfAh6tqj9Osnrg8eOTfCLJ04HzgVPofYIAeHhW6TH0Pg28GpgGng0EeBNwVPcp4AHgK0mOX/TGSyMw6LUS7QfeCXw2yR1JfofetMnHu9t/VNVWeoH82Oz5+FmOAv4aeH2STcCnDs3JJ7kO+CVgG3A18D/AA/TeOAK8JMmHuvV8D7gXuB+4BXgIeBD4OeB9VTUNfI7ep4jvjnUUpCE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1BvkzbMWHweOAV4K/DVrq45VXWwqh6ep2xB2bmUQe8VtX1DbWeSE4H3AvPOua1gw4zF5cC2qnpoYl0tj2HG4nnA9u6U5Q8DL51Qb5M2zFi8G3hjVV0BfA143YR6ezxaUHYuZbB6RW3fvNvZ7cV+HHh7Vd03udYmbpjf+bnAm5PsAp6b5IOTaW3ihhmLe4AN3fI00OprY5ixWAecnmQV8CLgiXxu+MKys6qW5AY8GbgDuIrex6wzgK3z1DxlqfpZztuQY/Em4EFgV3e7ZLn7Xq6xGKjftdw9L/Pr4nh6OwA3A7cBT1/uvpdxLF4I3Elvb/azwNrl7nuJx2RX9+85wFsGHjulG4s/B/6N3oHsOde1pBdMeUVt3xNlO4fhWPQ5Fn2OxcJ0XzlzFvCZmmdO3ytjJalxrR78lCR1DHpJapxBL0mNM+glqXEGvSQ17v8Abgi1rh+e0LQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10dac748>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "import matplotlib\n",
    "#matplotlib.rcParams['font.family'] = ['SimHei']\n",
    "#matplotlib.rcParams['font.sans-serif'] = 'NSimSun,Times New Roman'# 中文设置成宋体，除此之外的字体设置成New Roman \n",
    "\n",
    "plt.title('钟形函数')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "E:\\Anaconda3\\lib\\site-packages\\matplotlib\\mpl-data\\matplotlibrc\n"
     ]
    }
   ],
   "source": [
    "import matplotlib\n",
    "print(matplotlib.matplotlib_fname())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['观', '自', '在', '菩', '刹', '，', '形', '神']\n",
      "['自', '在', '菩', '刹', '，', '形', '神']\n"
     ]
    }
   ],
   "source": [
    "data = u'观自在菩刹，形神'\n",
    "raw_x = [ch for ch in data]\n",
    "raw_y = [ch for ch in data[1:]]\n",
    "print(raw_x)\n",
    "print(raw_y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.90914437 0.36150037 0.63392018]\n",
      "[41.  2.  3.]\n",
      "[2. 4. 6.]\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "import numpy.random as random\n",
    "\n",
    "\n",
    "state_tensor = tf.placeholder(  tf.float64, shape=[3], name='label')\n",
    "state_tensor = tf.constant(random.rand(3))\n",
    "\n",
    "w = tf.constant(dtype=tf.float64, value=[2.], shape=[1])\n",
    "matmul = tf.multiply(state_tensor, w) \n",
    "with tf.Session() as sess:\n",
    "    state = sess.run(state_tensor) # ,{state_tensor:[41,2,3]}\n",
    "    print(state)\n",
    "    state = sess.run(state_tensor ,{state_tensor:[41,2,3]}) #\n",
    "    print(state)\n",
    "    matmul_value = sess.run(matmul ,{state_tensor:[1,2,3]}) #\n",
    "    print(matmul_value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
